#include<iostream>
#include<algorithm>
#define MAXX 500001
#define N 100010
using namespace std;
typedef struct T
{
	int x;
	int y;
	int flag;
}T;
T t[N];
int X[MAXX+1];
int Y[MAXX+1];
int XY[MAXX+1];
int n,m;
int out[N/2];
int lowbit(int x)
{
	return x&(-x);
}
void init()
{
	memset(X,0,sizeof(X));
	memset(Y,0,sizeof(Y));
	memset(XY,0,sizeof(XY));
}
void insert(int *g,int v)
{
	while(v<=MAXX)
	{
		g[v]++;
		v+=lowbit(v);
	}
}
bool cmp(T a,T b)
{
	if(a.y!=b.y)return a.y<b.y;
	else return a.x<b.x;
}
int getsum(int *g,int v)
{
	int sum=0;
	while(v)
	{
		sum+=g[v];
		v-=lowbit(v);
	}
	return sum;
}
int main()
{
	int c;
	int i;
	int three;
	int two;
	int four;
	int ans;
	scanf("%d",&c);
	while(c--)
	{
		init();
		scanf("%d %d",&n,&m);
		for(i=0;i<n;i++)
		{
			scanf("%d %d",&t[i].x,&t[i].y);
			t[i].x++;
			t[i].y++;
			t[i].flag=0;
			insert(X,t[i].x);
			insert(Y,t[i].y);
		}
		for(;i<m+n;i++)
		{
			scanf("%d %d",&t[i].x,&t[i].y);
			t[i].flag=i-n+1;
		}
		sort(t,t+m+n,cmp);
		for(i=0;i<m+n;i++)
		{
			if(t[i].flag==0)
			{
				insert(XY,t[i].x);
			}
			else
			{
				three=getsum(XY,t[i].x);
				four=getsum(Y,t[i].y)-three;
				two=getsum(X,t[i].x)-three;
				ans=abs(2*two+2*four-n);
				out[t[i].flag]=ans;
			}
		}
		for(i=1;i<=m;i++)printf("%d\n",out[i]);
		printf("\n");
	}
	return 0;
}
